package com.sgb.kjwl.view.ui.fragment.packers;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentFigureCheckBinding;

import com.sgb.kjwl.model.entity.EmploymentEntity;
import com.sgb.kjwl.model.entity.TenderListEntity;
import com.sgb.kjwl.model.entity.packers.LabourServiceAndEmploymentEntity;
import com.sgb.kjwl.model.entity.self.SelfEmploymentEditEntity;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.NumberConstant;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.util.UserOperating;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LoginEvent;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.activity.packers.EmploymentApplyActivity;
import com.sgb.kjwl.view.ui.activity.packers.EmploymentDetailActivity;
import com.sgb.kjwl.view.ui.activity.packers.LaborServiceAndEmploymentDetailActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickInquireByLetterActivity;
import com.sgb.kjwl.view.ui.activity.pick.TenderDetailsActivity3;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.adapter.packers.LaborServiceAndEmploymentAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.PackerHallBidingAdapter;
import com.sgb.kjwl.view.ui.adapter.packers.PackersEmploymentAdapter;
import com.sgb.kjwl.view.widget.GoodsTypePopWindow4;
import com.sgb.kjwl.view.widget.MapCityWorkPopWindow;
import com.sgb.kjwl.view.widget.MapSubcontractPopWindow;
import com.sgb.kjwl.view.widget.MapTeamWorkPopWindow;
import com.sgb.kjwl.viewmodel.packers.FigureCheckViewModel;
import com.sgb.link.view.widget.CustomXTabLayout;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PermissionUtils;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.xrecyclerview.XRecyclerView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author younghow
 * @date 2021/8/17
 * description:工队图查
 */
public class FigureCheckFragment extends AppLazyFragment implements AMap.OnMarkerClickListener,
        AMap.OnCameraChangeListener {
    FigureCheckViewModel mViewModel;
    FragmentFigureCheckBinding mBinding;
    private double lat;
    private double log;
    private AMap aMap;
    //地图缩放比例
    private float mZoom = 11;
    //中心点经纬度
    private LatLng mCenterLatLng;
    //marker集合
    private final List<Marker> mMarkers = new ArrayList<>();
    //当前最后一个点击的marker
    private Marker mLastMarker;
    private String provinceName, cityName;
    int selectType = 0;
    Map<String, Object> mMap = new HashMap<>();
    private MapTeamWorkPopWindow workPopWindow;
    EmploymentEntity employmentEntity;
    LabourServiceAndEmploymentEntity mLabourEntity;
    int clickType;
    private MapCityWorkPopWindow cityWorkPopWindow;
    private boolean mIsLoadMoreEmployment;
    private boolean mIsLoadMoreLabourService;
    private boolean mIsLoadMoreHallBiding;
    private int mPageEmployment;
    private int mPageLabourService;
    private int mPageHallBiding;
    private String industryNo;
    private String industryName;
    private List<AddressEntity> mAddressEntities;
    private boolean mIsMap = true;

    private MapSubcontractPopWindow mapSubcontractPopWindow;

    private PackersEmploymentAdapter adapter;
    private PackerHallBidingAdapter mFindBuildAdapter;
    private LaborServiceAndEmploymentAdapter mAdapter;

    private final static int REQUEST_CODE = 10031;
    public static final int RESULT_OK = -1;
    private boolean mIsMarkClick;
    private GoodsTypePopWindow4 carsTypePopWindow;
    private int typePosition;
    private List<GoodsInfoTypeEntity3> carsTypeData;
    private boolean isSelectAuto;
    private TenderListEntity mTender;


    public static FigureCheckFragment getInstance() {
        return  new FigureCheckFragment();
    }

    public static FigureCheckFragment getInstance(boolean isHide) {
        FigureCheckFragment fragment = new FigureCheckFragment();
        Bundle bundle = new Bundle();
        bundle.putBoolean("isHide", isHide);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_figure_check, container, false);
        mViewModel = new ViewModelProvider(this).get(FigureCheckViewModel.class);
        mBinding.teamMap.onCreate(savedInstanceState);
        init();
        return mBinding.getRoot();
    }

    @Override
    protected void initView() {
        boolean isHide = false;
        if (getArguments() != null) {
            isHide = getArguments().getBoolean("isHide", false);
        }
        if (isHide){
            mBinding.topLayout.setVisibility(View.GONE);
        }
    }

    public void init() {
        mBinding.setLifecycleOwner(getActivity());
        mBinding.setOnClick(this);
        mBinding.tvPictureCheckSearch.setOnClickListener(this);
        mBinding.ivChangeListMap.setOnClickListener(this);
        mBinding.ivEmploymentAll.setOnClickListener(this);
        provinceName = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.Province, "新疆维吾尔自治区");
        cityName = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.City, "乌鲁木齐市");
        mBinding.cityName.setText(provinceName + cityName);
        workPopWindow = new MapTeamWorkPopWindow(getActivity());
        workPopWindow.setRootView(mBinding.teamMap);
        workPopWindow.setOnDismissListener(this::resetOtherMarker);
        mViewModel.getLinkAgeWorkType();
        carsTypeData = new ArrayList<>();

        cityWorkPopWindow = new MapCityWorkPopWindow(getActivity());
        cityWorkPopWindow.setRootView(mBinding.teamMap);
        cityWorkPopWindow.setOnDismissListener(this::resetOtherMarker);

        mapSubcontractPopWindow = new MapSubcontractPopWindow(getActivity());
        mapSubcontractPopWindow.setOnDismissListener(this::resetOtherMarker);

        adapter = new PackersEmploymentAdapter(getContext(), null, 0);
        adapter.setOnItemClick(new AdapterOnItemClick<EmploymentEntity>() {
            @Override
            public void onItemClick(EmploymentEntity employmentEntity, int position) {
                EmploymentDetailActivity.startForResult(getActivity(), employmentEntity.getNo(), employmentEntity.getProjectName(), employmentEntity.isIsApply(), 0);
            }
        });

        mAdapter = new LaborServiceAndEmploymentAdapter(getContext(), null);
        mAdapter.setOnItemClick(new AdapterOnItemClick<LabourServiceAndEmploymentEntity>() {
            @Override
            public void onItemClick(LabourServiceAndEmploymentEntity labourServiceAndEmploymentEntity, int position) {
                ActivityJump.jumpToActivityForResult(getActivity(), LaborServiceAndEmploymentDetailActivity.class, 0, Pair.create("no", labourServiceAndEmploymentEntity.getNo()), Pair.create("workNo", labourServiceAndEmploymentEntity.getWorkNo()), Pair.create("workName", labourServiceAndEmploymentEntity.getCategoryName()), Pair.create("isFocus", labourServiceAndEmploymentEntity.getIsFocus()), Pair.create("isApply", labourServiceAndEmploymentEntity.isApply()), Pair.create("mMomentNo", labourServiceAndEmploymentEntity.getUserNo()), Pair.create("workNameForList", labourServiceAndEmploymentEntity.getWorkName()), Pair.create("employmentType", labourServiceAndEmploymentEntity.getEmploymentType()), Pair.create("imId", labourServiceAndEmploymentEntity.getImId()));
            }
        });

        mFindBuildAdapter = new PackerHallBidingAdapter(getContext(), null);
        mFindBuildAdapter.setOnItemClick(new AdapterOnItemClick<TenderListEntity>() {
            @Override
            public void onItemClick(TenderListEntity tenderListEntity, int position) {
                TenderDetailsActivity3.start(getActivity(), tenderListEntity.getId() + "", 0);
            }
        });
        mFindBuildAdapter.onIChildClick(tenderListEntity -> TenderDetailsActivity3.start(getActivity(), tenderListEntity.getId() + "", 0));

        mBinding.xrvPictureCheck.setLayoutManager(new LinearLayoutManager(getContext()));
        mBinding.xrvPictureCheck.setAdapter(adapter);

        mBinding.tlTeamPictureCheck.addTab(mBinding.tlTeamPictureCheck.newTab().setText("用工需求"));
        mBinding.tlTeamPictureCheck.addTab(mBinding.tlTeamPictureCheck.newTab().setText("同城用工"));
        mBinding.tlTeamPictureCheck.addTab(mBinding.tlTeamPictureCheck.newTab().setText("工程分包"));
        mBinding.tlTeamPictureCheck.addOnTabSelectedListener(new CustomXTabLayout.SimpleSelectedListener(){
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                industryNo = "";
                selectType = tab.getPosition();
                isSelectAuto=false;
                mBinding.etPictureCheckSearch.setText("");
                industryName = "";
                setAdapter();
                if (selectType == 1 || selectType == 0) {
                    mBinding.etPictureCheckSearch.setHint("搜索工种名称");
//                    mBinding.etPictureCheckSearch.setVisibility(View.VISIBLE);
//                    mBinding.tvPictureCheckSearch.setVisibility(View.VISIBLE);
                    mViewModel.getLinkAgeWorkType();
                } else if (selectType == 2) {
                    mBinding.etPictureCheckSearch.setHint("搜索工程类别");
//                    mBinding.etPictureCheckSearch.setVisibility(View.GONE);
//                    mBinding.tvPictureCheckSearch.setVisibility(View.GONE);
                    mViewModel.getCategoryListTree();
                }
                getCurData();
            }
        });


        mBinding.etPictureCheckSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!TextUtils.isEmpty(mBinding.etPictureCheckSearch.getText().toString())) {

                }
            }
        });

        mBinding.xrvPictureCheck.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                loadData(false);
            }

            @Override
            public void onLoadMore() {
                loadData(true);
            }
        });

        initData();

        carsTypePopWindow = new GoodsTypePopWindow4(getActivity());
        carsTypePopWindow.setBgView(mBinding.grayLayout);
        carsTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object type, Object key2, Object key3) {
                GoodsInfoTypeEntity3 entity = (GoodsInfoTypeEntity3) type;
                typePosition = (int) key2;
                isSelectAuto=false;
                mBinding.etPictureCheckSearch.setText("");
                industryName = "";
                industryNo=entity.getNo();
                mBinding.tlTeamPictureCheckSecond.setScrollPosition(typePosition,0,true);
                getCurData();
            }
        });
        carsTypePopWindow.setOnDismissListener(() -> mBinding.ivEmploymentAll.setImageResource(R.mipmap.btn_expand_team_employment));
    }

    private void setAdapter() {
        if (selectType == 0) {
            mBinding.xrvPictureCheck.setAdapter(adapter);
        } else if (selectType == 1) {
            mBinding.xrvPictureCheck.setAdapter(mAdapter);
        } else {
            mBinding.xrvPictureCheck.setAdapter(mFindBuildAdapter);
        }
    }

    private void initData() {
        if (PermissionUtils.checkPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION)) {
            lat = NumberUtil.convertToDouble(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "0"));
            log = NumberUtil.convertToDouble(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "0"));
            mViewModel.getLocation(getActivity(), provinceName, cityName);
        } else {
            mViewModel.getLocation(getActivity(), "新疆维吾尔自治区", "乌鲁木齐市");
        }
        mViewModel.ldLatLng.observe(getActivity(), latLng -> {
            mCenterLatLng = latLng;
            aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mCenterLatLng, mZoom));
        });

        mViewModel.ldAddress.observe(getActivity(), address -> {
            if (!address.getProvince().contains(provinceName) || !address.getCity().contains(cityName)) {
                provinceName = address.getProvince();
                cityName = address.getCity();
                mBinding.cityName.setText(provinceName + cityName);
                mViewModel.findPositionByAddress(address.getProvince(), address.getCity(), "");
            }
        });

        mViewModel.ldGetData.observe(getActivity(), map -> {
            mMap = map;
            refreshMap(map);
        });

        mViewModel.ldEmployment.observe(getActivity(), data -> {
            if (employmentEntity != null) {//登录刷新数据
                for (EmploymentEntity entity : data) {
                    if (entity.getNo().equals(employmentEntity.getNo())) {
                        employmentEntity = entity;
                        workPopWindow.setData(entity);
                    }
                }
            }
            refreshEmploymentMapMarker(data);

        });
        mViewModel.ldLabour.observe(getActivity(), data -> {
            if (mLabourEntity != null) {//登录刷新数据
                for (LabourServiceAndEmploymentEntity entity : data) {
                    if (entity.getNo().equals(mLabourEntity.getNo())) {
                        mLabourEntity = entity;
                        cityWorkPopWindow.setData(entity);
                    }
                }
            }
            refreshLabourMapMarker(data);
        });
        mViewModel.ldTender.observe(getActivity(), data -> {
            if (mTender != null) {//登录刷新数据
                for (TenderListEntity entity : data) {
                    if (entity.getId().equals(mTender.getId())) {
                        mTender = entity;
                        mapSubcontractPopWindow.setData(entity);
                    }
                }
            }
            refreshSubcontractMapMarker(data);
        });

        mViewModel.ldDelEmployment.observe(getActivity(), isDel -> {
            switch (clickType) {
                case 1:
                    if (isDel) {
                        workPopWindow.dismiss();
                        MToast.showToast(getActivity(), "该用工已招满，请重新选择");
                        refreshMap(mMap);
                    } else {
                        SelfEmploymentEditEntity editEntity = new SelfEmploymentEditEntity();
                        editEntity.setCategoryName(employmentEntity.getCategoryName());
                        editEntity.setCategoryNo(employmentEntity.getCategoryNo());
                        editEntity.setIndustryNo(employmentEntity.getIndustryNo());
                        Intent intent = new Intent(getContext(), EmploymentApplyActivity.class);
                        intent.putExtra("no", employmentEntity.getNo());
                        intent.putExtra("entity", editEntity);
                        startActivityForResult(intent, REQUEST_CODE);
                    }
                    break;
                case 2:
                    if (isDel) {
                        workPopWindow.dismiss();
                        MToast.showToast(getActivity(), "该用工已失效，请重新选择");
                        refreshMap(mMap);
                    } else {
                        EmploymentDetailActivity.startForResult(FigureCheckFragment.this, employmentEntity.getNo(), employmentEntity.getProjectName(), employmentEntity.isIsApply(), 0);
                    }
                    break;
                default:
                    break;
            }
        });
        mViewModel.ldDelLabour.observe(getActivity(), isDel -> {
            switch (clickType) {
                case 1:
                    if (isDel) {
                        cityWorkPopWindow.dismiss();
                        MToast.showToast(getActivity(), "该用工已招满，请重新选择");
                        refreshMap(mMap);
                    } else {
                        com.sgb.kjwl.utils.DialogHelper.showDialogForTeam(getActivity(), "请确认报名信息", new String[]{"工种", "姓名", "联系电话"}, new String[]{mLabourEntity.getWorkName(), UserOperating.getInstance().getUserRealName(), UserOperating.getInstance().getPhone()}, "取消报名", "确认报名", new DialogFunction() {
                            @Override
                            public void normalRoundDialog() {
                                Map<String, Object> map = new HashMap<>();
                                map.put("relationNo", mLabourEntity.getNo());
                                map.put("workNo", mLabourEntity.getWorkNo());
                                mViewModel.apply(getActivity(), map);
                            }
                        });
                    }
                    break;
                case 2:
                    if (isDel) {
                        cityWorkPopWindow.dismiss();
                        MToast.showToast(getActivity(), "该用工已失效，请重新选择");
                        refreshMap(mMap);
                    } else {
                        ActivityJump.jumpToActivityForResult(FigureCheckFragment.this, LaborServiceAndEmploymentDetailActivity.class, 0, Pair.create("no", mLabourEntity.getNo()), Pair.create("workNo", mLabourEntity.getWorkNo()), Pair.create("workName", mLabourEntity.getCategoryName()), Pair.create("isFocus", mLabourEntity.getIsFocus()), Pair.create("isApply", mLabourEntity.isApply()), Pair.create("mMomentNo", mLabourEntity.getUserNo()), Pair.create("workNameForList", mLabourEntity.getWorkName()), Pair.create("employmentType", mLabourEntity.getEmploymentType()), Pair.create("imId", mLabourEntity.getImId()));
                    }
                    break;
            }
        });
        mViewModel.ldFollow.observe(getActivity(), isFollow -> {
            if (selectType == 0) {
                employmentEntity.setFocus(isFollow);
                workPopWindow.setData(employmentEntity);
            } else {
                mLabourEntity.setFocus(isFollow);
                cityWorkPopWindow.setData(mLabourEntity);
            }
        });
        mViewModel.mFocus.observe(getActivity(), isFollow -> {
            if (isFollow == 0) {
                mTender.setUserFocusFlag(1);
                mapSubcontractPopWindow.setData(mTender);
            } else {
                mTender.setUserFocusFlag(0);
                mapSubcontractPopWindow.setData(mTender);
            }
        });
        mViewModel.mSignUpSuccessLiveData.observe(getActivity(), signUp -> {
            mLabourEntity.setApply(true);
            cityWorkPopWindow.setData(mLabourEntity);
        });
// TODO IM功能目前需要全部去掉，此处需要后期IM迁移完成后完善
//        mViewModel.mImLiveData.observe(getViewLifecycleOwner(), this::buildSingleTalking);
//        mViewModel.mImbLiveData.observe(getViewLifecycleOwner(), this::buildSingleTalking);

        mViewModel.mImLiveData.observe(getViewLifecycleOwner(), this::buildSingleTalking);
        mViewModel.mImbLiveData.observe(getViewLifecycleOwner(), this::buildSingleTalking);

        mViewModel.mLoadGetData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.showProgressDialog(getContext(), null, "", 0, false, null).setCanceledOnTouchOutside(false));
        mViewModel.mSuccessGetData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.dismissProgressDialog());
        mViewModel.mFailGetData.observe(getViewLifecycleOwner(), aBoolean -> DialogHelper.dismissProgressDialog());

        mViewModel.getEmploymentList.observe(getViewLifecycleOwner(), employmentEntities -> {
            if (mIsLoadMoreEmployment) {
                mBinding.xrvPictureCheck.loadMoreComplete();
                if (employmentEntities != null && employmentEntities.size() > 0) {
                    adapter.addDatas(employmentEntities);
                }
                mBinding.xrvPictureCheck.setNoMore(employmentEntities.size() < 10);
            } else {
                mBinding.xrvPictureCheck.refreshComplete();
                if (employmentEntities != null && employmentEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    adapter.setDatas(employmentEntities);
                    mBinding.xrvPictureCheck.smoothScrollToPosition(0);
                    if (employmentEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.xrvPictureCheck.setNoMore(true);
                    }
                } else {
                    adapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);

                }
            }
        });

        mViewModel.getLabourList.observe(getViewLifecycleOwner(), new Observer<List<LabourServiceAndEmploymentEntity>>() {
            @Override
            public void onChanged(List<LabourServiceAndEmploymentEntity> labourServiceAndEmploymentEntities) {
                if (mIsLoadMoreLabourService) {
                    if (labourServiceAndEmploymentEntities != null && labourServiceAndEmploymentEntities.size() > 0) {
                        mAdapter.addDatas(labourServiceAndEmploymentEntities);
                    }
                    if (labourServiceAndEmploymentEntities != null) {
                        mBinding.xrvPictureCheck.setNoMore(labourServiceAndEmploymentEntities.size() < 10);
                    }
                    mBinding.xrvPictureCheck.setVisibility(View.VISIBLE);
                } else {
                    mBinding.xrvPictureCheck.refreshComplete();
                    if (labourServiceAndEmploymentEntities != null && labourServiceAndEmploymentEntities.size() > 0) {
                        mBinding.emptyView.setVisibility(View.GONE);
                        mAdapter.setDatas(labourServiceAndEmploymentEntities);
                        mBinding.xrvPictureCheck.smoothScrollToPosition(0);
                        if (labourServiceAndEmploymentEntities.size() < NumberConstant.NUMBER_TEN) {
                            mBinding.xrvPictureCheck.setNoMore(true);
                        }
                    } else {
                        mAdapter.clearDatas();
                        mBinding.emptyView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });

        mViewModel.getTenderList.observe(getViewLifecycleOwner(), tenderListEntities -> {
            if (mIsLoadMoreHallBiding) {
                mBinding.xrvPictureCheck.loadMoreComplete();
                if (tenderListEntities != null && tenderListEntities.size() > 0) {
                    mFindBuildAdapter.addDatas(tenderListEntities);
                }
                mBinding.xrvPictureCheck.setNoMore(tenderListEntities.size() < 10);
            } else {
                mBinding.xrvPictureCheck.refreshComplete();
                if (tenderListEntities != null && tenderListEntities.size() > 0) {
                    mBinding.emptyView.setVisibility(View.GONE);
                    mFindBuildAdapter.setDatas(tenderListEntities);
                    mBinding.xrvPictureCheck.smoothScrollToPosition(0);
                    if (tenderListEntities.size() < NumberConstant.NUMBER_TEN) {
                        mBinding.xrvPictureCheck.setNoMore(true);
                    }
                } else {
                    mFindBuildAdapter.clearDatas();
                    mBinding.emptyView.setVisibility(View.VISIBLE);
                }
            }
        });

        mViewModel.mSuccessWorkType.observe(getViewLifecycleOwner(), new Observer<List<AddressEntity>>() {
            @Override
            public void onChanged(List<AddressEntity> addressEntities) {
                mAddressEntities = addressEntities;
                carsTypeData.clear();
                for (AddressEntity addressEntity : addressEntities) {
                    GoodsInfoTypeEntity3 info = new GoodsInfoTypeEntity3();
                    info.setName(addressEntity.getName());
                    info.setNo(addressEntity.getNo());
                    carsTypeData.add(info);
                }
                mBinding.tlTeamPictureCheckSecond.removeAllTabs();
                mBinding.tlTeamPictureCheckSecond.clearOnTabSelectedListeners();
                for (AddressEntity addressEntity : addressEntities) {
                    mBinding.tlTeamPictureCheckSecond.addTab(mBinding.tlTeamPictureCheckSecond.newTab().setText(addressEntity.getName()));
                }
                mBinding.tlTeamPictureCheckSecond.scrollTo(0, 0);
                mBinding.tlTeamPictureCheckSecond.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                    @Override
                    public void onTabSelected(TabLayout.Tab tab) {
                        typePosition = tab.getPosition();

                        if (mAddressEntities != null && mAddressEntities.size() > 0) {
                            if (tab.getPosition() != 0) {
                                mBinding.etPictureCheckSearch.setText("");
                                industryName = "";
                            } else {
                                if (!isSelectAuto) {
                                    mBinding.etPictureCheckSearch.setText("");
                                    industryName = "";
                                }

                                if (!TextUtils.isEmpty(mBinding.etPictureCheckSearch.getText().toString())) {
                                    industryName = mBinding.etPictureCheckSearch.getText().toString();
                                } else {
                                    industryName = "";
                                }
                            }
                            industryNo = mAddressEntities.get(tab.getPosition()).getNo();
                            getCurData();
                            isSelectAuto = false;
                        }
                    }

                    @Override
                    public void onTabUnselected(TabLayout.Tab tab) {

                    }

                    @Override
                    public void onTabReselected(TabLayout.Tab tab) {

                    }
                });

            }
        });

        /**
         * 去到招标的详情页，h5页面
         */
        mViewModel.mUrlTenderLiveData.observe(getViewLifecycleOwner(), s -> {
            String[] split = s.split("----");
            WebViewX5HostActivity.start(getActivity(), split[1], split[0]);
        });

    }

    //刷新当前页数据
    private void refreshMap(Map<String, Object> map) {
        clearMarker();
        if (selectType == 0) {
            mLabourEntity = null;
            mTender=null;
            mViewModel.getEmploymentMap(getActivity(), map);
        } else if (selectType == 1) {
            employmentEntity = null;
            mTender=null;
            mViewModel.getLabourMap(getActivity(), map);
        } else {
            employmentEntity = null;
            mLabourEntity = null;

            HashMap mMap = new HashMap<>();
            mMap.put("sortMethod", "1");
            mMap.put("type", "4");
            mMap.put("provinceNo", map.get("provinceNo"));
            mMap.put("cityNo", map.get("cityNo"));
            if (!TextUtils.isEmpty(industryNo)) {
                mMap.put("goodsType", industryNo);
            }

            if (!TextUtils.isEmpty(industryName)) {
                mMap.put("goodsTypeName", industryName);
            }
            mViewModel.getProjectMap(getActivity(), mMap);
        }
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_picture_check_search) {
            isSelectAuto = true;

            if (typePosition != 0) {
                mBinding.tlTeamPictureCheckSecond.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (mBinding.tlTeamPictureCheckSecond.getTabAt(0) != null) {
                            mBinding.tlTeamPictureCheckSecond.getTabAt(0).select();
                        }
                    }
                }, 100);
            } else {
                if (!TextUtils.isEmpty(mBinding.etPictureCheckSearch.getText().toString())) {
                    industryName = mBinding.etPictureCheckSearch.getText().toString();
                } else {
                    industryName = "";
                }
                getCurData();
            }
        } else if (id == R.id.iv_change_list_map) {
            mIsMap = !mIsMap;
            if (mIsMap) {
                mBinding.rlPictureChekList.setVisibility(View.GONE);
                mBinding.rlPictureChekMap.setVisibility(View.VISIBLE);
                mBinding.ivChangeListMap.setImageResource(R.mipmap.team_picture_check_list);
            } else {
                mBinding.rlPictureChekList.setVisibility(View.VISIBLE);
                mBinding.rlPictureChekMap.setVisibility(View.GONE);
                mBinding.ivChangeListMap.setImageResource(R.mipmap.team_picture_check_map);
            }
            getCurData();
        } else if (id == R.id.iv_employment_all) {
            if (carsTypeData != null && carsTypeData.size() > 0) {
                carsTypePopWindow.setData(carsTypeData, typePosition);
                carsTypePopWindow.showPopwindow(mBinding.ivEmploymentAll, 0, 0);
            }
            mBinding.ivEmploymentAll.setImageResource(R.mipmap.btn_expand_up_gray);
        }
    }

    private void getCurData() {
        if (mIsMap) {

            if (!TextUtils.isEmpty(industryNo)) {
                mMap.put("industryNo", industryNo);
            } else {
                mMap.remove("industryNo");
            }

            if (!TextUtils.isEmpty(industryName)) {
                mMap.put("industryName", industryName);
            } else {
                mMap.remove("industryName");
            }

            refreshMap(mMap);
        } else {
            loadData(false);
        }
    }

    @Override
    protected void onLazyLoad() {
        initMap();
        DialogHelper.showProgressDialog(getActivity(), "数据加载中...");
        mViewModel.getAddressModel(getActivity(), provinceName, cityName);
    }

    /**
     * 初始化地图
     */
    private void initMap() {
        //获取地图控制类
        aMap = mBinding.teamMap.getMap();
        //显示定位蓝点
        aMap.getUiSettings().setMyLocationButtonEnabled(false);
        //显示缩放控制器
        aMap.getUiSettings().setZoomControlsEnabled(false);
        //marker点击监听
        aMap.setOnMarkerClickListener(this);
        //监听地图移动
        aMap.setOnCameraChangeListener(this);
    }

    /**
     * 清除页面marker
     */
    private void clearMarker() {
        aMap.clear();
        mMarkers.clear();
    }

    /**
     * 刷新地图覆盖物
     */
    private void refreshEmploymentMapMarker(List<EmploymentEntity> list) {

        if (list == null || list.size() == 0) {
            MToast.showToast(getActivity(), "暂无数据");
            return;
        }
        //添加新marker，清空历史marker
        for (EmploymentEntity entity : list) {
            if (entity.getLatitude() == null || entity.getLongitude() == null) {
                continue;
            }
            addEmploymentMarker(new LatLng(entity.getLatitude().doubleValue(), entity.getLongitude().doubleValue()),
                    R.mipmap.marker_worker, entity);

        }
    }

    /**
     * 添加覆盖物
     */
    private void addEmploymentMarker(LatLng latLng, @DrawableRes int drawable, EmploymentEntity entity) {
        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(latLng);
        Marker marker;
        if (employmentEntity != null && entity.getNo().equals(employmentEntity.getNo())) {//得到之前点击marker获取的实体，并更换点击图标
            markerOption.icon(BitmapDescriptorFactory.fromResource(R.mipmap.marker_big_worker));
            marker = aMap.addMarker(markerOption);
            mLastMarker = marker;
            employmentEntity = null;
        } else {
            markerOption.icon(BitmapDescriptorFactory.fromResource(drawable));
            marker = aMap.addMarker(markerOption);

        }
        //设置附着对象
        marker.setObject(entity);
        mMarkers.add(marker);
    }

    /**
     * 刷新地图覆盖物
     */
    private void refreshLabourMapMarker(List<LabourServiceAndEmploymentEntity> list) {
        clearMarker();
        if (list == null || list.size() == 0) {
            MToast.showToast(getActivity(), "暂无数据");
            return;
        }
        //添加新marker，清空历史marker
        for (LabourServiceAndEmploymentEntity entity : list) {
            if (entity.getLatitude() == null && entity.getLongitude() == null) {
                continue;
            }
            addLabourMarker(new LatLng(entity.getLatitude().doubleValue(), entity.getLongitude().doubleValue()),
                    R.mipmap.marker_worker, entity);
        }
    }

    /**
     * 添加覆盖物
     */
    private void addLabourMarker(LatLng latLng, @DrawableRes int drawable, LabourServiceAndEmploymentEntity entity) {
        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(latLng);
        Marker marker;
        if (mLabourEntity != null && entity.getNo().equals(mLabourEntity.getNo())) {
            markerOption.icon(BitmapDescriptorFactory.fromResource(R.mipmap.marker_big_worker));
            marker = aMap.addMarker(markerOption);
            mLastMarker = marker;
            mLabourEntity = null;
        } else {
            markerOption.icon(BitmapDescriptorFactory.fromResource(drawable));
            marker = aMap.addMarker(markerOption);

        }
        //设置附着对象
        marker.setObject(entity);
        mMarkers.add(marker);
    }


    /**
     * 刷新地图覆盖物
     */
    private void refreshSubcontractMapMarker(List<TenderListEntity> list) {
        clearMarker();
        if (list == null || list.size() == 0) {
            MToast.showToast(getActivity(), "暂无数据");
            return;
        }
        //添加新marker，清空历史marker
        for (TenderListEntity entity : list) {
            if (entity.getLocalLat() == null && entity.getLocalLng() == null) {
                continue;
            }
            addSubcontractMarker(new LatLng(Double.parseDouble(entity.getLocalLat()), Double.parseDouble(entity.getLocalLng())),
                    R.mipmap.marker_worker, entity);
        }


    }

    /**
     * 添加工程分包覆盖物
     */
    private void addSubcontractMarker(LatLng latLng, @DrawableRes int drawable, TenderListEntity entity) {
        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(latLng);
        Marker marker;
        if (mTender != null && entity.getId().equals(mTender.getId())) {
            markerOption.icon(BitmapDescriptorFactory.fromResource(R.mipmap.marker_big_worker));
            marker = aMap.addMarker(markerOption);
            mLastMarker = marker;
//            mTender = null;
        } else {
            markerOption.icon(BitmapDescriptorFactory.fromResource(drawable));
            marker = aMap.addMarker(markerOption);
        }
        //设置附着对象
        marker.setObject(entity);
        mMarkers.add(marker);
    }

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {

    }

    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        if (!mIsMarkClick) {
            mViewModel.getCityByLocation(getActivity(), cameraPosition.target.latitude, cameraPosition.target.longitude);
        }

    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        mIsMarkClick = true;


        marker.setIcon(BitmapDescriptorFactory.fromResource(R.mipmap.marker_big_worker));
        mLastMarker = marker;
        //0 临时用工图查 1 劳务用工 2:工程分包
        if (selectType == 0) {
            EmploymentEntity entity = (EmploymentEntity) marker.getObject();
            workPopWindow.setData(entity);
            workPopWindow.showPopwindow(mBinding.teamMap, Gravity.BOTTOM, 0, 0);
            mIsMarkClick = false;
            workPopWindow.setClickListener(new MapTeamWorkPopWindow.BtnClickListener() {
                @Override
                public void follow(EmploymentEntity entity) {
                    employmentEntity = entity;
                    if (UserOperating.getInstance().isNotLogged(getActivity())) {
                        return;
                    }

                    if (SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, "").equals(entity.getUserNo())) {
                        MToast.showToast(getActivity(), "自己不能关注自己发布的用工信息");
                    } else {
                        mViewModel.follow(getContext(), 4, !entity.isFocus(), entity.getNo());
                    }
                }

                @Override
                public void apply(EmploymentEntity entity) {
                    clickType = 1;
                    employmentEntity = entity;
                    if (!UserOperating.getInstance().isNotAuthReal(getActivity())) {
                        if (employmentEntity != null && employmentEntity.isIsApply()) {
                            MToast.showToast(getActivity(), "请勿重复报名");
                            return;
                        }

                        if (SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, "").equals(entity.getUserNo())) {
                            MToast.showToast(getActivity(), "自己不能报名自己发布的劳务用工");
                        } else {
                            mViewModel.isDelEmployment(getActivity(), entity.getNo());
                        }
                    }

                }

                @Override
                public void detail(EmploymentEntity entity) {
                    clickType = 2;
                    employmentEntity = entity;
                    mViewModel.isDelEmployment(getActivity(), entity.getNo());
                }

                @Override
                public void toIm(EmploymentEntity entity) {
                    employmentEntity = entity;
                    if (UserOperating.getInstance().isNotLogged(getActivity())) {
                        return;
                    }
                    if (employmentEntity.getUserNo().equals(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, ""))) {
                        MToast.showToast(getActivity(), "无法和自己交流");
                        return;
                    }
                    if (employmentEntity.getIsCompany() == 0) {
                        MToast.showToast(getActivity(), "该信息为个人用户发布，当前无法交流");
                        return;
                    }
                    if (employmentEntity.getIsCompany() == 1 && TextUtils.isEmpty(employmentEntity.getImAccount())) {
                        MToast.showToast(getActivity(), "未设置客服人员，无法交流");
                        return;
                    }
                    buildSingleTalking(employmentEntity.getImAccount());
                }

                @Override
                public void inquire(EmploymentEntity entity) {
                    employmentEntity = entity;
                    if (UserOperating.getInstance().isNotLogged(getActivity())) {
                        return;
                    }
                    if (employmentEntity.getUserNo().equals(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, ""))) {
                        MToast.showToast(getActivity(), "无法和自己函询");
                        return;
                    }
                    PickInquireByLetterActivity.start(getActivity(), employmentEntity.getNo(), "team", "", "", "3", employmentEntity.getProjectName());
                }

                @Override
                public void showContentPop() {
                    workPopWindow.showPopwindowBottom(mBinding.teamMap);
                }

                @Override
                public void toPhone(EmploymentEntity entity) {
                    if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                        VerificationCodeLoginActivity.start(getActivity(), false);
                    }else {
                        new RoundDialog.Builder(getContext())
                                .title("确认呼叫")
                                .content(entity.getContactPhone())
                                .cancel("取消")
                                .confirm("确定")
                                .contentGravity(Gravity.CENTER)
                                .cancelable(false)
                                .confirmCallback(view -> ActivityJump.jumpToPhone(getContext(),entity.getContactPhone()))
                                .show();
                    }
                }
            });

        } else if (selectType == 1) {
            LabourServiceAndEmploymentEntity labourEntity = (LabourServiceAndEmploymentEntity) marker.getObject();
            cityWorkPopWindow.setData(labourEntity);
            cityWorkPopWindow.showPopwindowBottom(mBinding.teamMap);
            mIsMarkClick = false;
            cityWorkPopWindow.setClickListener(new MapCityWorkPopWindow.BtnClickListener() {
                @Override
                public void follow(LabourServiceAndEmploymentEntity entity) {
                    mLabourEntity = entity;
                    if (UserOperating.getInstance().isNotLogged(getActivity())) {
                        return;
                    }

                    if (SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, "").equals(entity.getUserNo())) {
                        MToast.showToast(getActivity(), "自己不能关注自己发布的用工信息");
                    } else {
                        mViewModel.follow(getContext(), 6, !entity.isFocus(), entity.getNo());
                    }
                }

                @Override
                public void apply(LabourServiceAndEmploymentEntity entity) {
                    clickType = 1;
                    mLabourEntity = entity;
                    int companyType = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0);


                    if (!UserOperating.getInstance().isNotAuthReal(getActivity())) {
                        if (mLabourEntity != null && mLabourEntity.isApply()) {
                            MToast.showToast(getActivity(), "请勿重复报名");
                            return;
                        }
                        if (companyType == 0) {
                            if (SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, "").equals(mLabourEntity.getUserNo())) {
                                MToast.showToast(getActivity(), "自己不能报名自己发布的劳务用工");
                            } else {
                                mViewModel.isDelDeleteLabor(getContext(), entity.getNo());
                            }
                        } else {
                            MToast.showToast(getActivity(), "请前往用户中心将身份切换为个人才可报名");
                        }

                    }
                }

                @Override
                public void detail(LabourServiceAndEmploymentEntity entity) {
                    clickType = 2;
                    mLabourEntity = entity;
                    mViewModel.isDelDeleteLabor(getContext(), entity.getNo());

                }

                @Override
                public void toIm(LabourServiceAndEmploymentEntity mEntity) {
                    mLabourEntity = mEntity;
                    if (UserOperating.getInstance().isNotLogged(getActivity())) {
                        return;
                    }
                    if (mEntity.getUserNo().equals(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, ""))) {
                        MToast.showToast(getActivity(), "无法和自己交流");
                        return;
                    }
                    if (mEntity.getEmploymentType() == 2) {
                        MToast.showToast(getActivity(), "该信息为个人用户发布，当前无法交流");
                        return;
                    }
                    if (mEntity.getEmploymentType() == 1 && TextUtils.isEmpty(mEntity.getImId())) {
                        MToast.showToast(getActivity(), "未设置客服人员，无法交流");
                        return;
                    }
                    mViewModel.findCustomerServiceImAccount(getContext(), mEntity.getImId());
                }

                @Override
                public void inquire(LabourServiceAndEmploymentEntity mEntity) {
                    mLabourEntity = mEntity;
                    if (UserOperating.getInstance().isNotLogged(getActivity())) {
                        return;
                    }
                    if (mEntity.getUserNo().equals(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO, ""))) {
                        MToast.showToast(getActivity(), "无法和自己函询");
                        return;
                    }
                    PickInquireByLetterActivity.start(getActivity(), mEntity.getNo(), "team", "", "", "3", mEntity.getCategoryName(), "laborWorkDetail");
                }

                @Override
                public void showContentPop() {
                    cityWorkPopWindow.showPopwindowBottom(mBinding.teamMap);
                }

                @Override
                public void toPhone(LabourServiceAndEmploymentEntity entity) {
                    if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                        VerificationCodeLoginActivity.start(getActivity(), false);
                    }else {
                        new RoundDialog.Builder(getContext())
                                .title("确认呼叫")
                                .content(entity.getContactNumber())
                                .cancel("取消")
                                .confirm("确定")
                                .contentGravity(Gravity.CENTER)
                                .cancelable(false)
                                .confirmCallback(view -> ActivityJump.jumpToPhone(getContext(),entity.getContactNumber()))
                                .show();
                    }
                }
            });

        } else {
            mTender = (TenderListEntity) marker.getObject();
            mapSubcontractPopWindow.setData(mTender);
            mapSubcontractPopWindow.showPopwindowBottom(mBinding.teamMap);
            mapSubcontractPopWindow.setBtnClickListener(new MapSubcontractPopWindow.BtnClickListener() {
                @Override
                public void follow(TenderListEntity entity) {
                    mViewModel.editTender(getActivity(), entity.getId(), entity.getUserFocusFlag());
                }

                @Override
                public void toIm(String customerServiceImAccount) {
                    mViewModel.mImbLiveData.postValue(customerServiceImAccount);
                }

                @Override
                public void toDetail(TenderListEntity entity) {
                    TenderDetailsActivity3.start(getActivity(), entity.getId() + "", 0);
                }
            });
            mIsMarkClick = false;
        }
        return false;
    }

    /**
     * 还原其他marker
     */
    private void resetOtherMarker() {
        if (mLastMarker != null) {
            mLastMarker.setIcon(BitmapDescriptorFactory.fromResource(R.mipmap.marker_worker));
            mLastMarker = null;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        mBinding.teamMap.onResume();
        if (NumberConstant.sIsChangeForTeam == 1){
            refreshMap(mMap);
            NumberConstant.sIsChangeForTeam = -1;
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        mBinding.teamMap.onPause();
    }

    @Override
    public void onSaveInstanceState(@NotNull Bundle outState) {
        super.onSaveInstanceState(outState);
        mBinding.teamMap.onSaveInstanceState(outState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
        mBinding.teamMap.onDestroy();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {//临时用工详情操作报名后更新
            if (requestCode == REQUEST_CODE) {
                employmentEntity.setIsApply(true);
                workPopWindow.setData(employmentEntity);
            }
        } else if (resultCode == 1) {//临时用工详情操作关注报名后更新
            if (requestCode == 0) {
                boolean isFocus = data.getBooleanExtra("isFocus", false);
                boolean isApply = data.getBooleanExtra("isApply", false);
                employmentEntity.setIsApply(isApply);
                employmentEntity.setFocus(isFocus);
                workPopWindow.setData(employmentEntity);
            }
        } else if (resultCode == 2) {//劳务用工详情操作关注报名后更新
            if (requestCode == 0) {
                boolean isFocus = data.getBooleanExtra("isFocus", false);
                boolean isApply = data.getBooleanExtra("isApply", false);
                mLabourEntity.setApply(isApply);
                mLabourEntity.setIsFocus(isFocus);
                cityWorkPopWindow.setData(mLabourEntity);
            }
        } else if (resultCode == 3) {
            if (requestCode == 0) {
                boolean isFocus = data.getBooleanExtra("isFocus", false);
                if (isFocus) {
                    mTender.setUserFocusFlag(1);
                } else {
                    mTender.setUserFocusFlag(0);
                }
                mapSubcontractPopWindow.setData(mTender);
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(LoginEvent event) {
        if (event == null) {
            return;
        }
        if (event.getMessageTag() == EventConstant.EVENT_LOGIN) {//登录成功
            refreshMap(mMap);
        } else if (event.getMessageTag() == EventConstant.EVENT_LOGIN_OUT) {//退出登录
            employmentEntity = null;
            mLabourEntity = null;
            mTender = null;
            refreshMap(mMap);

        }
        EventBus.getDefault().removeStickyEvent(event);
    }

    private void loadData(boolean isLoadMore) {
        if (selectType == 0) {
            mIsLoadMoreEmployment = isLoadMore;
            if (isLoadMore) {
                mPageEmployment++;
            } else {
                mPageEmployment = 1;
            }

            Map<String, Object> map = new HashMap<>();
            map.put("limit", 10);
            map.put("page", mPageEmployment);
            if (!TextUtils.isEmpty(industryNo)) {
                map.put("industryNo", industryNo);
            }

            if (!TextUtils.isEmpty(industryName)) {
                map.put("industryName", industryName);
            }

            if (!TextUtils.isEmpty((CharSequence) mMap.get("provinceNo"))) {
                map.put("provinceNo", mMap.get("provinceNo"));
            }

            if (!TextUtils.isEmpty((CharSequence) mMap.get("cityNo"))) {
                map.put("cityNo", mMap.get("cityNo"));
            }

            if (!TextUtils.isEmpty((CharSequence) mMap.get("areaNoList"))) {
                List<String> stringList = new ArrayList<>();
                stringList.add((String) mMap.get("areaNoList"));
                map.put("areaNoList", stringList);
            }

            mViewModel.getEmployment(map);
        } else if (selectType == 1) {
            mIsLoadMoreLabourService = isLoadMore;
            if (isLoadMore) {
                mPageLabourService++;
            } else {
                mPageLabourService = 1;
            }
            Map<String, Object> map = new HashMap<>();
            map.put("industryNo", industryNo);
            map.put("industryName", industryName);
            map.put("provinceNo", mMap.get("provinceNo"));
            map.put("cityNo", mMap.get("cityNo"));
            List<String> stringList = new ArrayList<>();
            if (mMap.get("areaNoList") != null) {
                stringList.add((String) mMap.get("areaNoList"));
            }
            map.put("areaNo", stringList);
            map.put("limit", 10);
            map.put("page", mPageLabourService);
            mViewModel.getLabourList(map);
        } else {
            mIsLoadMoreHallBiding = isLoadMore;
            if (isLoadMore) {
                mPageHallBiding++;
            } else {
                mPageHallBiding = 1;
            }
            Map<String, Object> map = new HashMap<>();
            map.put("limit", 10);
            map.put("page", mPageHallBiding);
            if (!"".equals(mMap.get("provinceNo")) && mMap.get("provinceNo") != null) {
                map.put("areacode", mMap.get("provinceNo"));
            }
            if (!"".equals(mMap.get("cityNo")) && mMap.get("cityNo") != null) {
                map.put("city", mMap.get("cityNo"));
            }
            map.put("comName", "");
            map.put("type", "4");
            map.put("sortMethod", "1");
            if (!TextUtils.isEmpty(industryNo)) {
                map.put("goodsType", industryNo);
            }

            if (!TextUtils.isEmpty(industryName)) {
                map.put("goodsTypeName", industryName);
            }
            mViewModel.getNewList(map);
        }
    }
}
